package cn.edu.xhu.library_management.area.mapper;

import cn.edu.xhu.library_management.area.entity.LmArea;
import cn.edu.xhu.library_management.area.entity.search.LmAreaSearch;
import cn.edu.xhu.library_management.area.entity.vo.LmAreaVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2022 - 08 - 29
 * @Description: 区域mapper类
 */
public interface AreaMapper {
    /**
     * 通过楼层ID，获取所有区域
     * @param FloorId 楼层ID
     * @return 区域对象集合
     */
    @Select("select *from lm_area where fl_id = #{floorId}")
    @Results(id = "AreaMap",value = {
            @Result(id = true,column = "ar_id",property = "id"),
            @Result(column = "ar_number",property = "number"),
            @Result(column = "ar_type",property = "type"),
            @Result(column = "ar_remain_capacity",property = "remainCapacity"),
            @Result(column = "ar_total_capacity",property = "totalCapacity"),
            @Result(column = "fl_id",property = "floorId")
    })
    public List<LmArea> findAreasByFloorId(Integer FloorId);

    @Select("select * from lm_area where ar_id = #{id};")
    @ResultMap("AreaMap")
    public LmArea findAreaById(Integer id);

    @Select("select * from lm_area where ar_number = #{number} and fl_id = #{floorId}")
    @ResultMap("AreaMap")
    public LmArea findAreaByNumberAndFloorId(@Param("number") char number,@Param("floorId") Integer floorId);

    public List<LmAreaVo> search(LmAreaSearch search);
    /**
     * 添加区域
     * @param area 区域对象
     * @return 返回受影响的行数
     */
    @Insert("insert into lm_area(ar_number,ar_type,ar_remain_capacity,ar_total_capacity,fl_id) " +
            "values (#{number},#{type},#{remainCapacity},#{totalCapacity},#{floorId})")
    public int addArea(LmArea area);

    public int updateArea(LmArea area);

    /**
     * 通过区域ID，删除区域
     * @param id 区域ID
     * @return 返回受影响的行数
     */
    @Delete("delete from lm_area where ar_id = #{id}")
    public int deleteAreaById(Integer id);
}
